package com.loren.demo32.tenant;

import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class CustomTenantResolver implements CurrentTenantIdentifierResolver {

    private static final ThreadLocal<String> TenantContext = new ThreadLocal<>();

    public void setCurrentTenant(String tenant) {
        TenantContext.set(tenant);
    }

    public void removeCurrentTenant() {
        TenantContext.remove();
    }

    @Override
    public String resolveCurrentTenantIdentifier() {
        return Optional.ofNullable(TenantContext.get()).orElse("multi_00");
    }

    @Override
    public boolean validateExistingCurrentSessions() {
        return false;
    }
}
